<template>
	<div>
		<el-row>
			<el-col :span="24">
				<el-form :model="formData" ref="formDataRef" :rules="rules" label-width="100px">
					<el-form-item label="合作方名称:" prop="Name">
						<el-input placeholder="请输入合作方名称" v-model="formData.Name"></el-input>
					</el-form-item>
					<el-form-item label="合作方电话:" prop="Phone">
						<el-input placeholder="请输入合作方电话" v-model="formData.Phone"></el-input>
					</el-form-item>
					<el-form-item label="身份证号码:" prop="IDcard">
						<el-input placeholder="请输入身份证号码" v-model="formData.IDcard"></el-input>
					</el-form-item>
					<el-form-item label="开放信息:" prop="Publicinfo">
						<el-input placeholder="请输入开放信息" v-model="formData.Publicinfo"></el-input>
					</el-form-item>
					<el-form-item label="编号:" prop="Number">
						<el-input placeholder="请输入编号" v-model="formData.Number"></el-input>
					</el-form-item>
					<el-form-item align="right">
						<el-button type="primary" style="width: 100%;" @click="insertHandler">添加</el-button>
					</el-form-item>
				</el-form>
			</el-col>
		</el-row>
	</div>
</template>

<script>
	export default {
		props: {
			closeFun: {
				type: Function,
				required: true
			},
		},
		data() {
			return {
				formData: {
					Name: "",
					Phone: "",
					IDcard: "",
					Publicinfo: "",
					Number: ""
				},
				rules: {
					Name: [{
						required: true,
						message: '请输入合作方名称',
						trigger: 'blur'
					}],
					// Phone: [{
					// 	required: true,
					// 	message: '请输入合作方电话',
					// 	trigger: 'blur'
					// }],
					// IDcard: [{
					// 	required: true,
					// 	message: '请输入身份证号码',
					// 	trigger: 'blur'
					// }],
					// Publicinfo: [{
					// 	required: true,
					// 	message: '请输入开放信息',
					// 	trigger: 'blur'
					// }],
					// Number: [{
					// 	required: true,
					// 	message: '请输入编号',
					// 	trigger: 'blur'
					// }],
				},
			}
		},
		methods: {
			insertHandler() {
				this.$refs.formDataRef.validate(valid => {
					if (valid) {
						this.$http.post('/api/Supplier/Insert/insert', this.formData).then(res => {
							const {
								StatusCode,
								Data,
								Message
							} = res.data || 0
							if (StatusCode == 200) {
								this.$message.success('添加成功')
								this.resetFieldsEvent()
								this.$parent.$parent.dialogAddForm.show = false
								this.closeFun()
							} else {
								this.$message.warning(Message)
							}
						})
					}
				})
			},
			resetFieldsEvent(){
				this.$refs.formDataRef.resetFields()
			}
		}
	}
</script>

<style>
</style>